<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class CheckLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //判断用户是否登录，如果没有登录，就强制用户去登录
        if (!Auth::check()){
            //设置闪存信息并跳转到登录
            session()->flash('danger','请先登录，再操作！');

            return redirect()->route('login');
        }
        return $next($request);
    }
}
